---
layout: example
category: example
title: Change a map's language
description: Using .setLayoutProperty to switch languages dynamically.
---
<style>
    #languageButtons {
        width: 90%;
        margin: 0 auto;
    }
    .language-switch-button {
        display: inline-block;
        position: relative;
        cursor: pointer;
        width: 20%;
        padding: 8px;
        border-radius: 3px;
        margin-top: 10px;
        font-size: 12px;
        text-align: center;
        color: #fff;
        background: #ee8a65;
        font-family: sans-serif;
        font-weight: bold;
    }
</style>
<div id='map'></div>
<ul id="languageButtons">
    <li onclick='switchLanguage("fr");' class='language-switch-button'>French</li>
    <li onclick='switchLanguage("ru");' class='language-switch-button'>Russian</li>
    <li onclick='switchLanguage("de");' class='language-switch-button'>German</li>
    <li onclick='switchLanguage("es");' class='language-switch-button'>Spanish</li>
</ul>
<script>
var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/light-v8',
    center: [16.05, 48],
    zoom: 2.9
});

function switchLanguage(language) {
    // Use setLayoutProperty to set the value of a layout property in a style layer.
    // The three arguments are the id of the layer, the name of the layout property,
    // and the new property value.
    map.setLayoutProperty('country-label-lg', 'text-field', '{name_' + language + '}');
}
</script>
